﻿using DevExpress.XtraBars.Ribbon;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace DevTeam
{
    public class Session
    {
        public class LookupMap
        {
            public int LookupId;
            public string Caption, CaptionEN, CaptionIT;

            public LookupMap(int LookupId, string Caption)
            {
                this.LookupId = LookupId;
                this.Caption = Caption;
            }
        }

        public static Dictionary<string, LookupMap> LookupMaps = new Dictionary<string, LookupMap>();

        public static bool NotificationsEnabled = true;

        public static User CurrentUser { get; set; }

        public static bool Notifications = true;

        public static int WhoAmI { get { return CurrentUser.UserId; } }

        public static int[] Admins = new int[] { };
        public static int[] Developers = new int[] { };

        public static void SetAdmins(params int[] UserIds)
        {
            Admins = UserIds;
        }

        public static void SetDevelopers(params int[] UserIds)
        {
            Developers = UserIds;
        }

        public static PrgSettings Settings { get; set; }

        public static EasyNav EasyNav;

        public static PrgSettings PrgSettingsOrg { get; set; }

        public static RepositoryManager repositoryManager { get; set; }


        public static void Init(DevForm optionsForm, Dictionary<string, string> savedLookups, int userRepositoryId) //, DataManager AppDataManager)
        {
            //Aşağıdaki parçacık design time da static constructor larda yaşanan sorunları bertaraf etmesi için gerekli.            
            //if (LicenseManager.UsageMode == LicenseUsageMode.Runtime)

            Session.UserRepositoryId = userRepositoryId;

            OptionsForm = optionsForm;

            SavedLookups = savedLookups;
        }

        public static Dictionary<string, string> SavedLookups = new Dictionary<string, string>();

        public static DevForm OptionsForm;

        public static double Usd, Eur, Gbp;

        public static string DebugInfo { get; set; }

        static DateTime dtStart;
        static string watcherName;

        public static void AddDebugInfo(string Info)
        {
#if (DEBUG)
            DebugInfo += Info + Environment.NewLine;
            Debug.WriteLine(Info);
#endif
        }

        public static void StopWatcher()
        {
            AddDebugInfo(watcherName + ":\t" + (DateTime.Now - dtStart).TotalMilliseconds + " (ms)");
        }

        public static void StartWatcher(string Name)
        {
            if (dtStart != null)
                StopWatcher();

            dtStart = DateTime.Now;
            watcherName = Name;
        }

        public static DevMainForm MainForm { get; set; }

        public static int DataFileSize;

        public static double AcilisSuresi;
        public static DateTime LaunchingTime;

        public static bool InvalidateStoklar = false;

        public static string SQLiteFile;
        public static string SQLiteFileDelete
        {
            get
            {
                return Session.SQLiteFile + "Delete";
            }
        }

        public static string GununKurlari { get; set; }

        static public DataManager DataManager { get; set; }

        public static string Version { get; set; }

        //public static string DatabaseName { get; set; }

        public static string TempDirectory { get; set; }

        public static string AppDataPath { get; set; }

        public static string ServerAddress { get; set; }

        public static string ApplicationName { get; set; }

        public static string MessengerUserName { get; set; }

        public static string MessengerPassword { get; set; }



        public static int UserRepositoryId { get; set; }

        public static RibbonControl RibbonControl { get; set; }

        private static string getLookUpUpdatesSP = "GetUpdates2";

        public static string GetLookUpUpdatesSP
        {
            get { return Session.getLookUpUpdatesSP; }
            set { Session.getLookUpUpdatesSP = value; }
        }

        private static string getDeletedRowsSp = "GetDeletedRows";
        public static string GetDeletedRowsSp
        {
            get { return Session.getDeletedRowsSp; }
            set { Session.getDeletedRowsSp = value; }
        }

        private static string getLookupColumnsSp = "GetLookUps1";
        public static string GetLookupColumnsSp
        {
            get { return Session.getLookupColumnsSp; }
            set { Session.getLookupColumnsSp = value; }
        }

        private static string getLookupMapSp = "GetLookupMap";
        public static string GetLookupMapSp
        {
            get { return Session.getLookupMapSp; }
            set { Session.getLookupMapSp = value; }
        }


        public static string SkinName { get; set; }

        public static bool isProduction { get; set; }

        public class DevApplication
        {
            public DevApplication(string ApplicationName, string SQLiteFileName)
            {
                Session.isProduction = true;
                Session.ApplicationName = ApplicationName;
                Session.TempDirectory = FileManager.CreateTempFolder(ApplicationName);
                Session.AppDataPath = FileManager.CreateAppDataFolder(ApplicationName);
                Session.SQLiteFile = Session.AppDataPath + "\\" + Session.DatabasePostFix + SQLiteFileName;
            }
        }

        public static string DatabasePostFix
        {
            get
            {
                return isProduction ? "" : "TEST";
            }
        }

        public static string DatabaseTipi
        {
            get
            {
                return isProduction ? "CANLI" : "TEST";
            }
        }


        public static bool isProblematicUser
        {
            get
            {
                List<int> ids = new List<int>();
                ids.Add(509);//ali poze
                ids.Add(28);//tuğba kulak

                if (Session.CurrentUser != null)
                    return ids.Contains(Session.CurrentUser.UserId);
                else
                    return false;
            }
        }
    }
}
